<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>商品评价</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="{{URL::asset('layui/css/layui.css')}}"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-group">
        <button class="layui-btn layui-btn-primary layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>新增</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<script src="{{URL::asset('layui/layui.js')}}" charset="utf-8"></script>
<script src="{{URL::asset('js/jquery-3.1.1.min.js')}}"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    layui.use('table', function(){
        var table = layui.table;
        var id = "{{$id}}";
        table.render({
            elem: '#test'
            ,url:'/admin/goods/ping/api/list'
            ,where:{"id":id}
            ,toolbar: '#toolbarDemo'
            ,title: '商品评价表'
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
                ,{field:'nickname', title:'用户昵称', templet:function (d) {
                        if (d.user){
                            return d.user.nickname;
                        } else{
                            return '用户已删除';
                        }
                    }}
                ,{field:'order_sn', title:'订单号'}
                ,{field:'image', title:'图片', templet:function (d) {
                        if (d.image.length) {
                            var jd = '';
                            $.each(d.image,function (i,v) {
                               jd += '&nbsp;<img src="'+v+'"  width="50px" height="50px"/>';
                            });
                            return jd;
                        }else{
                            return '未评价图片';
                        }
                    }}
                ,{field:'content', title:'内容'}
                ,{field:'created_at', title:'评价时间'}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:80}
            ]]
            ,page: true
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'add':
                    var data = checkStatus.data;
                    layer.open({
                        type:2,
                        area:["90%","80%"],
                        title:"新增评价",
                        content:'/admin/ping/html/add?id='+id
                    });
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('该操作将永久删除此数据,是否确认?', function(index){
                    $.post('/admin/goods/ping/api/delete',{"id":data.id},function (d) {
                        if (d.code==200){
                            obj.del();
                        } else{
                            layer.msg("删除失败");
                        }
                    });
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                layer.prompt({
                    formType: 2
                    ,value: data.email
                }, function(value, index){
                    obj.update({
                        email: value
                    });
                    layer.close(index);
                });
            }
        });
    });
</script>

</body>
</html>